package com.eastfair.home.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.eastfair.annotation.annotation.log.SysLog;
import com.eastfair.boot.request.PageParams;
import com.eastfair.core.base.R;
import com.eastfair.home.service.CategoryService;
import com.eastfair.venueservice.dto.ServiceCategoryDTO;
import com.eastfair.venueservice.dto.ServiceCategoryPageQuery;
import com.eastfair.venueservice.vo.ServiceCategoryVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * 服务分类
 * </p>
 *
 * @author lyw
 * @date 2022-08-08
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/category")
@Api(value = "category", tags = "服务分类")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    /**
     * 查询服务分类列表分页
     *
     * @param params
     * @return
     */
    @ApiOperation(value = "查询服务分类列表分页")
    @PostMapping(value = "/queryCategoryList")
    public R<Page<ServiceCategoryVO>> queryCategoryList(@RequestBody PageParams<ServiceCategoryPageQuery> params) {
        Page<ServiceCategoryVO> r = categoryService.queryCategoryList(params);
        return R.success(r);
    }

    /**
     * 保存服务分类
     *
     * @param serviceCategoryDTO
     * @return
     */
    @ApiOperation(value = "保存服务分类")
    @SysLog("添加服务分类")
    @PostMapping(value = "/saveCategoryInfo")
    public R<Boolean> saveCategoryInfo(@RequestBody @Validated(ServiceCategoryDTO.Save.class) ServiceCategoryDTO serviceCategoryDTO) {

        return R.success(categoryService.saveCategoryInfo(serviceCategoryDTO));
    }

    /**
     * 修改服务分类
     *
     * @param serviceCategoryDTO
     * @return
     */
    @ApiOperation(value = "修改服务分类")
    @SysLog("修改服务分类")
    @PostMapping(value = "/updateCategoryById")
    public R<Boolean> updateCategoryById(@RequestBody @Validated(ServiceCategoryDTO.Update.class) ServiceCategoryDTO serviceCategoryDTO) {

        return R.success(categoryService.updateCategoryById(serviceCategoryDTO));
    }


    /**
     * 删除服务分类
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "删除服务分类")
    @SysLog("删除服务分类")
    @GetMapping(value = "/delCategoryById/{id}")
    public R<Boolean> delCategoryById(@PathVariable("id") Long id) {

        return R.success(categoryService.delCategoryById(id));
    }

    /**
     * 查询服务分类列表
     * @param categoryType
     * @return
     */
    @GetMapping(value = "/getCategoryList/{categoryType}/{exhibitionManageId}")
   public R<List<ServiceCategoryVO>> getCategoryListByExhibitionManageId(@PathVariable("categoryType") Integer categoryType,@PathVariable("exhibitionManageId") Long exhibitionManageId){
        List<ServiceCategoryVO> categoryVOList =categoryService.getCategoryListByExhibitionManageId(categoryType,exhibitionManageId);
         return   R.success(categoryVOList);
    }


}
